# coding=utf-8
import os

import requests

from inter_auto.utils.utils import Utils
from inter_auto.utils.utils import path

class BaseApi:

    def __init__(self):
        self.session = requests.session()
        self.path = path


    def get_cfg_data(self):
        env = os.getenv('env', default='test')
        yaml_path = f"{self.path}/inter_auto/config/{env}_env.yaml"
        data = Utils.get_data_yaml(yaml_path)
        return data

    def get(self,url,params):
        """
        get请求
        :param url:
        :param params:
        :return:
        """
        try:
            res = self.session.get(url,params=params)
            return res
        except Exception as e:
            res = {"msg":f"接口请求失败！{e}"}
            return res


    def post(self,url,params:dict=None):
        """
        post请求,请求内容的类型为application/json
        :param url:
        :param params:
        :return:
        """
        try:
            res = self.session.post(url,json=params)
            return res
        except Exception as e:
            res = {"msg":f"接口请求失败！{e}"}
            return res



if __name__ == '__main__':
    base = BaseApi()
    res = base.get_cfg_data()
    print(type(res))
    print(res.get("test"))

